@isTest
public class WorkOrderProductControllerTest
{
    static testMethod void WorkOrderProductControllerTest()
    {   
        Id ldcProfile = [Select Id From Profile Where Name like '%工程师%' limit  1  ].Id;

         User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         CompanyName= 'Y-MKSY',
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Username = 'Matldc1@test.com.maike',
                         Province__c = '四川省',
                         ManagerId = UserInfo.getUserId(),
                         FederationIdentifier ='123451', 
                         ResponseCode__c = 'TTTT' );
         insert u1; 

        Account acc=new Account();
    	acc.Name='Test1229J';
    	insert acc;


         Product__c p = TestUtils.createProduct();
        p.Brand__c = '迈克';
        p.Category3__c = '仪器';
        p.Category0__c = '仪器';
        p.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p.NCCode__c = '1001110000';
        insert p;


         Equipment__c e1 = new Equipment__c();
        e1.Account__c = acc.Id;
        e1.IMEINumber__c = '11';
        e1.Product__c = p.Id;
        insert e1;


    	Case cas=new Case();
    	cas.AccountId=acc.Id;
        cas.Engineer__c = u1.Id ;
        cas.ServiceManufacture__c = e1.Id;
    	insert cas;

       

       
        
    	
    	WorkOrder__c wo=new WorkOrder__c();
    	wo.Case__c=cas.Id;
    	wo.Account__c=acc.Id;
    	wo.Status__c='处理中';
        wo.Technician__c  = u1.Id ;
        wo.ServiceManufacture__c =e1.Id; 
    	insert wo;
        


        String wid=wo.Id;
         Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '配件';
         p1.Brand__c = '迈克';
        p1.Category3__c = '配件';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        p1.NCCode__c = '1101110000';
        insert p1;       

      

         
            PartsLendingApplication__c pla = new PartsLendingApplication__c();
            pla.IsSycToNc__c = true;
            pla.InventoryOrganization__c = 'MKSY';
            pla.OwnerId = u1.Id;
            insert pla;

            PartsLendingDetails__c pld = new PartsLendingDetails__c();
            pld.Product__c = p1.Id;
            pld.No__c =5;
            pld.A_InvoiceNo__c = 1;
            pld.A_WarrantyNo__c =1;
            pld.B_No__c = 5;
            pld.PartsLendingApplication__c = pla.Id;
            insert pld;



            PageReference page2 = new PageReference('/apex/CreateWorkOrderProduct?id='+wo.Id);
            System.Test.setCurrentPage(page2);

            WorkOrderProductController pra = new WorkOrderProductController();
            pra.setNil();
            pra.companyCode = 'MKSY';
            pra.init();
            pra.getSearch();


            Map<String,Object> saveMap =new Map<String,Object>();
            Map<String,String> baseMap =new Map<String,String>();

            baseMap.put('DocumentTypes__c','库存其他出库单');
            baseMap.put('InventoryOrganization__c', 'MKSY');
            saveMap.put('base', baseMap);

            saveMap.put('datas', JSON.deserializeUntyped(EncodingUtil.urlDecode(pra.dataJson, 'UTF-8')));
            System.debug('WorkOrderProductControllerTest==>'+saveMap);
            pra.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap), 'UTF-8');
            pra.save();

            System.debug(pra.msg);

            pra.init();

         


        


        
    }
}